package com.cuitrip.business.webview.proxy;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;

import com.alibaba.fastjson.JSONObject;
import com.cuitrip.business.home.recommend.model.ShareCard;
import com.cuitrip.business.webview.WebBrowserActivity;
import com.cuitrip.service.R;
import com.cuitrip.util.ResourceUtil;
import com.lab.jumper.Jumper;

/**
 * 价格逻辑代理类
 * Created by ak on 15/9/23.
 */
public class WebViewProxy {


    private static WebViewProxy sInstance;

    public static WebViewProxy getInstance() {
        if (null == sInstance)
            sInstance = new WebViewProxy();
        return sInstance;
    }

    public boolean browseWeb(Context context, String url) {
        return browseWeb(context, url, null, true);
    }


    public boolean browseWeb(Context context, String url, ShareCard shareCard){
        return browseWeb(context, url, null, true,shareCard);
    }


    public boolean browseWeb(Context context, String url, boolean showTitleBar) {
        return browseWeb(context, url, null, showTitleBar);
    }

    public boolean browseWeb(Context context, String url, JSONObject jsonObject) {
        return browseWeb(context, url, jsonObject,true);
    }



    public boolean browseWeb(Context context, String url, JSONObject jsonObject, boolean showTitleBar) {
        if (!TextUtils.isEmpty(url) && null != context) {
            Intent intent = new Intent(context, WebBrowserActivity.class);
            intent.putExtra(WebBrowserActivity.PARAM_URL, url);
            if (null != jsonObject) {
                intent.putExtra(WebBrowserActivity.PARAM_OBJECT, jsonObject.toJSONString());
            }
            intent.putExtra(WebBrowserActivity.PARAM_WEB_TITLE, context.getString(R.string.trip_attribute_description));
            intent.putExtra(WebBrowserActivity.KEY_SHOW_TITLE, showTitleBar);
            Jumper.launchActivity(context, intent);
            return true;
        }
        return false;
    }

    public boolean browseWeb(Context context, String url, JSONObject jsonObject, boolean showTitleBar,ShareCard shareCard) {
        if (!TextUtils.isEmpty(url) && null != context) {
            Intent intent = new Intent(context, WebBrowserActivity.class);
            intent.putExtra(WebBrowserActivity.PARAM_URL, url);
            if (null != jsonObject) {
                intent.putExtra(WebBrowserActivity.PARAM_OBJECT, jsonObject.toJSONString());
            }
            intent.putExtra(WebBrowserActivity.PARAM_SHARE_CARD,shareCard);
            intent.putExtra(WebBrowserActivity.PARAM_WEB_TITLE, context.getString(R.string.trip_attribute_description));
            intent.putExtra(WebBrowserActivity.KEY_SHOW_TITLE, showTitleBar);

            Jumper.launchActivity(context, intent);
            return true;
        }
        return false;
    }

    public boolean browseWeb(Context context, String url,String webTitle) {
        if (!TextUtils.isEmpty(url) && null != context) {
            Intent intent = new Intent(context, WebBrowserActivity.class);
            intent.putExtra(WebBrowserActivity.PARAM_URL, url);
            intent.putExtra(WebBrowserActivity.PARAM_WEB_TITLE,webTitle);
            intent.putExtra(WebBrowserActivity.PARAM_USE_WEB_TITLE,true);
            Jumper.launchActivity(context, intent);
            return true;
        }
        return false;
    }

}
